package DuiXingShuZu_3;

public class PhoneTest {
    public static void main(String[] args) {
        //定义数组存储3部手机对象
        //手机的属性：品牌、价格、颜色
        //要求：计算出三部手机的平均价格

        //1.创建数组存储对象
        Phone[] arr = new Phone[3];

        //2.创捷三个手机对象
        Phone p1 = new Phone("小米",3999.9,"蓝色");
        Phone p2 = new Phone("苹果",8889.9,"黑色");
        Phone p3 = new Phone("华为",4999.9,"红色");

        //3.把手机对象添加到数组当中
        arr[0] = p1;
        arr[1] = p2;
        arr[2] = p3;

        //4.求价格平均值
        double sum = 0;
        for (int i = 0; i < arr.length; i++) {
            //i索引，arr[i] 元素（手机对象）
            Phone phone = arr[i];
            sum = sum + phone.getPrice();
        }

        //5.求平均值
        double avg = sum / arr.length;
        System.out.println(avg);

    }
}
